package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.MonitoringPoint;
import com.ruoyi.system.service.IAirQualityDataService;
import com.ruoyi.system.service.IMonitoringPointService;

/**
 * 空气质量数据 控制器
 */
@RestController
@RequestMapping("/system/air-quality")
public class AirQualityController extends BaseController
{
    @Autowired
    private IAirQualityDataService airQualityDataService;
    
    @Autowired
    private IMonitoringPointService monitoringPointService;

    /**
     * 获取空气质量指数(AQI)的时间变化数据
     * 
     * @param pointId 监测点ID，可为null表示查询所有监测点
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @return 时间和AQI值的映射集合
     */
    @GetMapping("/aqi-time-data")
    public AjaxResult getAqiTimeData(Long pointId, String startTime, String endTime)
    {
        List<Map<String, Object>> data = airQualityDataService.selectAqiTimeData(pointId, startTime, endTime);
        return AjaxResult.success(data);
    }
    
    /**
     * 获取各监测点的空气质量分布数据
     * 
     * @return 监测点位置和AQI值的映射集合
     */
    @GetMapping("/aqi-distribution-data")
    public AjaxResult getAqiDistributionData()
    {
        List<Map<String, Object>> data = airQualityDataService.selectAqiDistributionData();
        return AjaxResult.success(data);
    }
    
    /**
     * 获取空气质量监测点列表
     * 
     * @return 监测点列表
     */
    @GetMapping("/monitoring-points")
    public AjaxResult getAirMonitoringPoints()
    {
        List<MonitoringPoint> points = monitoringPointService.selectAirMonitoringPoints();
        return AjaxResult.success(points);
    }
    
    /**
     * 获取监测点详情
     * 
     * @param pointId 监测点ID
     * @return 监测点信息
     */
    @GetMapping("/monitoring-point/{pointId}")
    public AjaxResult getMonitoringPoint(@PathVariable("pointId") Long pointId)
    {
        MonitoringPoint point = monitoringPointService.selectMonitoringPointByPointId(pointId);
        return AjaxResult.success(point);
    }
}